//
//  UITextField+Extension.m
//  Budejie
//
//  Created by 华杨科技 on 2017/10/9.
//  Copyright © 2017年 饶波. All rights reserved.
//

#import "UITextField+Extension.h"

@implementation UITextField (Extension)

- (void)setPlaceholderColor:(UIColor *)placeholderColor {
    
    // 提前设置占位文字；目的:让他提前创建占位label（placeholderLabel）
    NSString *oldPlaceholder = self.placeholder;
    self.placeholder = @" "; 
    self.placeholder = oldPlaceholder;
    
    // 占位文字颜色恢复默认值
    if (placeholderColor == nil) {
        placeholderColor = [UIColor colorWithRed:0 green:0 blue:0.0980392 alpha:0.22];
    }
   
    // 设置占位文字颜色
    [self setValue:placeholderColor forKeyPath:@"placeholderLabel.textColor"];
}

//- (void)setPlaceholderColor:(UIColor *)placeholderColor {
//    
//    // 提前设置占位文字；目的:让他提前创建占位label（placeholderLabel）
////    self.placeholder = @" ";
//    
//    [self setValue:placeholderColor forKeyPath:@"placeholderLabel.textColor"];
//}

- (UIColor *)placeholderColor {
    return [self valueForKeyPath:@"placeholderLabel.textColor"];
}
@end
